<template>
  <div>
    <div class="container-box">
      <div class="tableName">
        <p>通知公告/编辑通知公告</p>
    </div>
    <div class="table-search">
            <div class="title">
                <label for="" class="input-label" style=" vertical-align:center">* 标题:</label> <input type="text" placeholder="请输入" v-model="noticeTitle">
            </div>
            <div>
                <label for="" style=" vertical-align:top">* 内容:</label> <textarea name="" id="" cols="30" rows="10" v-model="noticeContent"></textarea>
            </div>
            <div class="btn-box">
                <div class="send"><button style="background-color:#fff;color:#333 ;border:1px soild #e4e4e4;" @click="quit">取消</button><button style="background-color:rgb(64,158,255);color:#fff; border:none;" @click="Save">保存</button><button  style="background-color:rgb(64,158,255);color:#fff;border:none;" @click="SavePub">保存并发布</button></div>
            </div>
    </div>
    </div>
  </div>
</template>

<script>
import axios from '@/util/http'
import {defineComponent,onMounted,ref} from 'vue'
import {useRouter,useRoute, } from 'vue-router'
import { ElMessage, ElMessageBox } from 'element-plus'
export default defineComponent({
    name:'addnotice',
    setup(){
      
      const router = useRouter()
      const route = useRoute()
      const noticeContent = ref('')
      const noticeTitle = ref('')
      const quit = ()=>{
        router.push('/notice')
      }
      const noticeId =useRouter().currentRoute._value.query.noticeId
      // const title =router.currentRoute._value.query.title
      // const context =router.currentRoute._value.query.context
      const createDate = new Date().toLocaleString()
      console.log(createDate)
      const SavePub = ()=>{
        ElMessageBox.confirm(
          '是否确认保存并发布该公告？',
          '删除确认',
          {
            confirmButtonText: '确认',
            cancelButtonText: '取消',
            type: 'warning',
          }
        )
          .then(async () => {
           await axios({method:'post',url:'notice/addNotice',data:{
          "createDate": new Date(),
          "createPeople": "李二牛",
          "noticeContent": noticeContent.value,
          "noticeTitle": noticeTitle.value,
          "releaseDate": new Date(),
          "status": 1
        }}).then((res)=>{
        })
            ElMessage({
              type: 'success',
              message: 'Delete completed',
            })
          })
          .catch(() => {
            ElMessage({
              type: 'info',
              message: 'Delete canceled',
            })
          })
        
        router.push('/notice')
      }
      onMounted( async()=>{
        await axios({method:'get',url:'notice/detailsNotice',params:{noticeId:noticeId}}).then((res)=>{
          noticeTitle.value = res.data.data.data[0].noticeTitle
          noticeContent.value = res.data.data.data[0].noticeContent
        })
      })
      const Save = ()=>{
        ElMessageBox.confirm(
          '是否确认发布该公告？',
          '删除确认',
          {
            confirmButtonText: '确认',
            cancelButtonText: '取消',
            type: 'warning',
          }
        )
          .then(async () => {
            await axios({method:'post',url:'notice/addNotice',data:{
          "createDate": new Date(),
          "createPeople": "李二牛",
          "noticeContent": noticeContent.value,
          "noticeTitle": noticeTitle.value,
          "releaseDate": null,
          "status": 0
        }}).then((res)=>{
        })
            ElMessage({
              type: 'success',
              message: 'Delete completed',
            })
          })
          .catch(() => {
            ElMessage({
              type: 'info',
              message: 'Delete canceled',
            })
          })
       
        router.push('/notice')
      }
return{
  quit,SavePub,Save,noticeContent,noticeTitle
}
    }
    
})
</script>

<style scoped lang="less">
label{
    color: #333;
    font-size: 13px;
    margin-right:10px;
}
input{
    width: 600px;
    height: 40px;
    padding: 2px 2px 2px 10px;
    font-family: "PingFangSC-Regular", "PingFang SC", sans-serif;
    font-weight: 400;
    font-style: normal;
    font-size: 12px;
    letter-spacing: normal;
    color: #333333;
    vertical-align: none;
    text-align: left;
    border: 1px solid #e4e4e4;
    border-radius:5px ;
    outline: none;
}
textarea{
    width: 70%;
    height: 380px;
    border: 1px solid #e4e4e4;
    resize: none;
    outline: none;
    color: rgb(188,188,188);
    padding: 2px 2px 2px 2px;
    font-family: "PingFangSC-Regular", "PingFang SC", sans-serif;
    font-weight: 400;
    font-style: normal;
    font-size: 13px;
    letter-spacing: normal;
}
.container-box{
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  background-color:#f5f5f5;
  color: #333;
  font-size: 13px;
}
.tableName{
  height: 45px;
  box-sizing: border-box;
  padding: 14px 0px;
}

.table-search{
  box-sizing: border-box;
  padding: 40px 80px;
    border-width: 0px;
    /* position: absolute;
    left: 0px;
    top: 0px; */
    width: 100%;
    height: 845px;
    background: inherit;
    background-color: rgb(255, 255, 255);
    border: none;
    border-radius: 4px;
    -moz-box-shadow: none;
    -webkit-box-shadow: none;
    box-shadow: none;
    font-family: 'Microsoft Tai Le Regular', 'Microsoft Tai Le', sans-serif;
    font-weight: 400;
    font-style: normal;
    font-size: 14px;
    color: #666666;
    text-align: left;
    line-height: 18px;
}
.title{
    margin-bottom: 40px;
}
.btn-box{
    display: flex;
    justify-content: center;
    padding-top:256px ;
    color: #fff;
}
/deep/.btn-box>.send> button{
    margin-left:20px;
    padding: 12px 32px;
    border-radius: 5px;
    border-color: #e4e4e4;
}



</style>